package com.encoder;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.utils.json.JsonUtils;
import com.vo.ChatMessageVO;

import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;

/**
 * 消息解码
 */
public class ChatMessageDecoder implements Decoder.Text<ChatMessageVO> {
    @Override
    public ChatMessageVO decode(String s) throws DecodeException {
        ChatMessageVO message = JsonUtils.readValue(s,ChatMessageVO.class);
        return message;
    }

    /**
     * 返回true才会真正进入到decode方法进行解码操作
     * @param s
     * @return
     */
    @Override
    public boolean willDecode(String s) {
        return true;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
